package org.twb.o2o.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.twb.o2o.domain.User;
import org.twb.o2o.service.UserService;

import java.util.List;

/**
 * Created by km on 2017/4/20.
 */
@RestController
public class UserRestController {
    @Autowired
    private UserService userService;

    @RequestMapping(value = "/api/user/{id}", method = RequestMethod.GET)
    public User findOneCity(@PathVariable(value = "id") Long id) {
        return userService.findById(id);
    }

    @RequestMapping(value = "/api/user", method = RequestMethod.GET)
    public List<User> findAll()
    {
        return userService.findAll();
    }

    @RequestMapping(value = "/api/user/delete/{id}",method = RequestMethod.GET)
    public void delete(@PathVariable(value = "id") Long id){
        userService.delete(id);
    }

    @RequestMapping(value = "/api/user", method = RequestMethod.POST)
    public void saveUser(@RequestBody User user) {
        userService.saveUser(user);
    }
    //
//    @RequestMapping(value = "/api/user/{userName}",method = RequestMethod.POST)
//    public void searchUser(@RequestBody)
}
